package com.df.hitime.common.config;


import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * @Description:
 * @Author: huangwl
 * @CreateDate: 2018/11/23 14:35
 */
@Component
public class MyWebMvcConfigurer implements WebMvcConfigurer {

    @Resource
    private Config config;
    /**
     * 处理跨越问题
     * @param registry
     */
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedHeaders("*")
                .allowedOrigins("*")
                .allowCredentials(true)
                .allowedMethods("GET", "POST", "DELETE", "PUT", "PATCH");

    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //配置上传资源文件路径与磁盘资源文件映射关系
        registry.addResourceHandler("/upload//**").addResourceLocations("file:"+config.getUploadPath()+"upload/");
    }


}
